package railRoad.io.files;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import railRoad.exception.OpenFileException;
import railRoad.io.AbstractReaderWriter;

/**
 * Abstract file for files read/write routine
 * 
 * @see AbstractReaderWriter
 * @author Rukin
 * 
 */
public abstract class FileWriteRead extends AbstractReaderWriter {

	private InputStream in;
	// Scanner in;
	private OutputStream out;

	public InputStream getIn() {
		return in;
	}

	public OutputStream getOut() {
		return out;
	}

	@Override
	public void open(String in, String out) throws Exception {
		try {
			if (in != null)
				this.in = new FileInputStream(in);
			if (out != null)
				this.out = new FileOutputStream(out);
		} catch (FileNotFoundException e) {
			throw new OpenFileException(e.getMessage());
		}

	}

	@Override
	public void close() throws IOException {
		if (in != null)
			in.close();

		if (out != null)
			out.close();
	}
}
